package table

import (
	"io"
	"strconv"
)

type FType uint

const (
	Invalid FType = iota
	Bool
	Int
	Int8
	Int16
	Int32
	Int64
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Uintptr
	Float32
	Float64
	Complex64
	Complex128
	Array
	Chan
	Func
	Interface
	Map
	Ptr
	Slice
	String
	Struct
	UnsafePointer
)

type TFields []*TField

// field attribute
type TField struct {
	FieldType  FType
	FieldKey   string
	FieldValue interface{}
	io.Writer
	FieldValStr string
	IsIndex     bool
	IsSearch    bool
}

func NewTFiled(fKey string, fVal interface{}, fType FType, isIndex bool) *TField {
	return &TField{
		FieldType:  fType,
		FieldKey:   fKey,
		FieldValue: fVal,
		//FieldKV:    make(map[string]string),
		IsIndex: isIndex,
	}
}

func (t *TField) GetVal() string {
	switch t.FieldType {
	case String:
		return t.FieldValue.(string)
	case Int64:
		return strconv.FormatInt(t.FieldValue.(int64), 10)
	case Int:
		return strconv.Itoa(t.FieldValue.(int))
	case Bool:
		return strconv.FormatBool(t.FieldValue.(bool))
	}
	return ""
}

func (t *TField) buildFiled() {
	t.FieldValStr = t.GetVal()
}
